home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / list.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  25.5 KB  |  799 lines

  1. #ifndef __STD_LIST__
  2. #define __STD_LIST__
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * list - list declarations for the Standard Library
  8.  *
  9.  * $Id: list,v 1.71 1996/09/30 02:28:53 smithey Exp $
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * Copyright (c) 1994
  14.  * Hewlett-Packard Company
  15.  *
  16.  * Permission to use, copy, modify, distribute and sell this software
  17.  * and its documentation for any purpose is hereby granted without fee,
  18.  * provided that the above copyright notice appear in all copies and
  19.  * that both that copyright notice and this permission notice appear
  20.  * in supporting documentation.  Hewlett-Packard Company makes no
  21.  * representations about the suitability of this software for any
  22.  * purpose.  It is provided "as is" without express or implied warranty.
  23.  *
  24.  *
  25.  ***************************************************************************
  26.  *
  27.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  28.  * ALL RIGHTS RESERVED *
  29.  * The software and information contained herein are proprietary to, and
  30.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  31.  * intends to preserve as trade secrets such software and information.
  32.  * This software is furnished pursuant to a written license agreement and
  33.  * may be used, copied, transmitted, and stored only in accordance with
  34.  * the terms of such license and with the inclusion of the above copyright
  35.  * notice.  This software and information or any other copies thereof may
  36.  * not be provided or otherwise made available to any other person.
  37.  *
  38.  * Notwithstanding any other lease or license that may pertain to, or
  39.  * accompany the delivery of, this computer software and information, the
  40.  * rights of the Government regarding its use, reproduction and disclosure
  41.  * are as set forth in Section 52.227-19 of the FARS Computer
  42.  * Software-Restricted Rights clause.
  43.  * 
  44.  * Use, duplication, or disclosure by the Government is subject to
  45.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  46.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  47.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  48.  * P.O. Box 2328, Corvallis, Oregon 97339.
  49.  *
  50.  * This computer software and information is distributed with "restricted
  51.  * rights."  Use, duplication or disclosure is subject to restrictions as
  52.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  53.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  54.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  55.  * then the "Alternate III" clause applies.
  56.  *
  57.  **************************************************************************/
  58.  
  59.  
  60. #include <stdcomp.h>
  61.  
  62. #ifndef _RWSTD_HEADER_REQUIRES_HPP
  63. #include <algorithm>
  64. #include <iterator>
  65. #include <memory>
  66. #include <stdexcept>
  67. #else
  68. #include <algorithm.hpp>
  69. #include <iterator.hpp>
  70. #include <memory.hpp>
  71. #include <stdexcept.hpp>
  72. #endif 
  73.  
  74. #ifndef list
  75. #define list list
  76. #endif
  77.  
  78.  
  79. #ifndef _RWSTD_NO_NAMESPACE
  80. namespace std {
  81. #endif
  82.  
  83. //
  84. // Note that _RWSTD_SIMPLE_DEFAULT(x)
  85. // will expand to: ' = x', or nothing,
  86. // depending on your compiler's capabilities and/or
  87. // flag settings (see stdcomp.h).
  88. //
  89. template <class T, class Allocator _RWSTD_SIMPLE_DEFAULT(allocator<T>) >
  90. class list
  91. {
  92.   protected:
  93.     struct list_node;
  94.     friend struct list_node;
  95.  
  96. #ifdef _RWSTD_ALLOCATOR
  97.     typedef _TYPENAME Allocator::rebind<void>::other::pointer  void_pointer;
  98. #else
  99.     typedef allocator_interface<Allocator,T>::void_pointer void_pointer;
  100. #endif
  101.  
  102.     struct list_node
  103.     {
  104.         ~list_node() { ; }
  105.         void_pointer next;
  106.         void_pointer prev;
  107.         T            data;
  108.     };
  109.  
  110.  
  111.     struct list_node_buffer;
  112.     friend struct list_node_buffer;
  113.  
  114. #ifdef _RWSTD_ALLOCATOR
  115.     typedef _TYPENAME Allocator::rebind<list_node>::other list_node_alloc_type;
  116.     typedef _TYPENAME Allocator::rebind<T>::other     value_alloc_type;
  117.     typedef _TYPENAME Allocator::rebind<list_node_buffer>::other buffer_alloc_type;
  118. #else
  119.     typedef allocator_interface<Allocator,list_node>  list_node_alloc_type;
  120.     typedef allocator_interface<Allocator,T>          value_alloc_type;
  121.     typedef allocator_interface<Allocator,list_node_buffer>   buffer_alloc_type;
  122. #endif
  123.     typedef _TYPENAME list_node_alloc_type::pointer       link_type;
  124.  
  125.     Allocator the_allocator;
  126.  
  127.   public:
  128.     //
  129.     // types
  130.     //
  131.     typedef Allocator                          allocator_type;
  132.     typedef T                                  value_type;
  133.     typedef value_alloc_type::size_type        size_type;
  134.     typedef value_alloc_type::difference_type  difference_type;
  135.     typedef value_alloc_type::reference        reference;
  136.     typedef value_alloc_type::const_reference  const_reference;
  137.  
  138.   protected:
  139.  
  140.     size_type buffer_size;
  141.  
  142.     struct list_node_buffer
  143.     {
  144.         ~list_node_buffer() { ; }
  145.         void_pointer next_buffer;
  146.         size_type    size;
  147.         link_type    buffer;
  148.     };
  149.     
  150.   protected:
  151.  
  152.     typedef _TYPENAME value_alloc_type::pointer        pointer;
  153.     typedef _TYPENAME value_alloc_type::const_pointer  const_pointer;
  154.     typedef _TYPENAME buffer_alloc_type::pointer       buffer_pointer;
  155.  
  156.     buffer_pointer                buffer_list;
  157.     link_type                     free_list;
  158.     link_type                     next_avail;
  159.     link_type                     last;
  160.     
  161.     void add_new_buffer (size_type n)
  162.     {
  163.         buffer_pointer tmp = 
  164.                      buffer_alloc_type(the_allocator).allocate(
  165.                      _RWSTD_STATIC_CAST(size_type,1),buffer_list);
  166.         tmp->buffer = list_node_alloc_type(the_allocator).allocate(n,last);
  167.         tmp->next_buffer = buffer_list;
  168.         tmp->size = n;
  169.         buffer_list = tmp;
  170.         next_avail = buffer_list->buffer;                
  171.         last = next_avail + n;
  172.     }
  173.     void deallocate_buffers ();
  174.     link_type get_node (size_type n)
  175.     {
  176.         link_type tmp = free_list;
  177.         return free_list ? (free_list = (link_type)(free_list->next), tmp) 
  178.             : (next_avail == last ? (add_new_buffer(n), next_avail++) 
  179.                : next_avail++);
  180.     }
  181.     void put_node (link_type p) { p->next = free_list; free_list = p; }
  182.  
  183.  
  184.   protected:
  185.     
  186.     link_type node;
  187.     size_type length;
  188.  
  189.   public:
  190.     
  191.     class iterator;
  192.     class const_iterator;
  193.     friend class iterator;
  194.     friend class const_iterator;
  195.  
  196.     class iterator : public bidirectional_iterator<T, difference_type>
  197.     {
  198.         friend class list<T,Allocator>;
  199.         friend class const_iterator;
  200.  
  201.       protected:
  202.       
  203.         link_type node;
  204.         iterator (link_type x) : node(x) {}
  205.     
  206.       public:
  207.  
  208.         iterator () {}
  209.         bool operator== (const iterator& x) const { return node == x.node; }
  210.         bool operator!= (const iterator& x) const { return !(*this == x); }
  211.         reference operator* () const { return (*node).data; } 
  212.         iterator& operator++ ()
  213.         { 
  214.             node = (link_type)((*node).next); return *this;
  215.         }
  216.         iterator operator++ (int)
  217.         {
  218.             iterator tmp = *this; ++*this; return tmp;
  219.         }
  220.         iterator& operator-- ()
  221.         {
  222.             node = (link_type)((*node).prev); return *this;
  223.         }
  224.         iterator operator-- (int)
  225.         {
  226.             iterator tmp = *this; --*this; return tmp;
  227.         }
  228.     };  // End of definition of iterator class.
  229.  
  230.     class const_iterator : public bidirectional_iterator<T, difference_type>
  231.     {
  232.         friend class list<T,Allocator>;
  233.  
  234.       protected:
  235.       
  236.         link_type node;
  237.         const_iterator (link_type x) : node(x) {}
  238.     
  239.       public:
  240.  
  241.         const_iterator () {}
  242.         const_iterator (const iterator& x) : node(x.node) {}
  243.         bool operator== (const const_iterator& x) const {return node==x.node;}
  244.         bool operator!= (const const_iterator x) const { return !(*this == x); } 
  245.         const_reference operator* () const { return (*node).data; }
  246.         const_iterator& operator++ ()
  247.         { 
  248.             node = (link_type)((*node).next); return *this;
  249.         }
  250.         const_iterator operator++ (int)
  251.         {
  252.             const_iterator tmp = *this; ++*this; return tmp;
  253.         }
  254.         const_iterator& operator-- ()
  255.         {
  256.             node = (link_type)((*node).prev); return *this;
  257.         }
  258.         const_iterator operator-- (int)
  259.         {
  260.             const_iterator tmp = *this;
  261.             --*this;
  262.             return tmp;
  263.         }
  264.     };  // End of definition of const_iterator class.
  265.  
  266.     typedef _STD::reverse_bidirectional_iterator<const_iterator, value_type,
  267.                                 const_reference, const_pointer, difference_type>
  268.             const_reverse_iterator;
  269.     typedef _STD::reverse_bidirectional_iterator<iterator, value_type, reference,
  270.                                            pointer,difference_type>
  271.             reverse_iterator;
  272.  
  273.     //
  274.     // construct/copy/destroy
  275.     //
  276.     list (const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator())) 
  277.          : length(0), the_allocator(alloc), buffer_list(0),
  278.            free_list(0), next_avail(0), last(0)
  279.     {
  280.        init(1);
  281.     }
  282.     
  283. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS    
  284.     list (void) 
  285.          : length(0), the_allocator(Allocator()), buffer_list(0),
  286.            free_list(0), next_avail(0), last(0)
  287.     {
  288.        init(1);
  289.     }
  290. #endif
  291.     //
  292.     // Build a list of size n with each element set to default for type T.
  293.     // This requires that T have a default constructor.
  294.     //
  295.     _EXPLICIT list (size_type n, const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator())) 
  296.          : length(0), the_allocator(alloc), buffer_list(0),
  297.            free_list(0), next_avail(0), last(0)
  298.     {
  299.         init(n);
  300.         T value;
  301.         insert(begin(), n, value);
  302.     }
  303.  
  304. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  305.     _EXPLICIT list (size_type n) 
  306.          : length(0), the_allocator(Allocator()), buffer_list(0),
  307.            free_list(0), next_avail(0), last(0)
  308.     {
  309.         T value;
  310.         init(n);
  311.         insert(begin(), n, value);
  312.     }
  313.  
  314.     list (size_type n, const T& value)
  315.          : length(0), the_allocator(Allocator()), buffer_list(0),
  316.            free_list(0), next_avail(0), last(0)
  317.     {
  318.         init(n)
  319.         insert(begin(), n, value);
  320.     }
  321. #endif
  322.  
  323. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  324.     template<class InputIterator>
  325.     list (InputIterator first, InputIterator locallast,
  326.                     const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  327.          : length(0), the_allocator(alloc), buffer_list(0),
  328.            free_list(0), next_avail(0), last(0)
  329.     { 
  330.         init();
  331.         insert(begin(), first, locallast);
  332.     }
  333.     list (int n, const T& value,
  334.               const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  335.           : the_allocator(alloc)
  336.     { init(n); insert(begin(), n, value); }
  337.     list (unsigned int n, const T& value,
  338.               const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  339.           : the_allocator(alloc)
  340.     { init(n); insert(begin(), n, value); }
  341.     list (long n, const T& value,
  342.               const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  343.           : the_allocator(alloc)
  344.     { init(n); insert(begin(), n, value); }
  345.     list (unsigned long n, const T& value,
  346.               const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  347.           : the_allocator(alloc)
  348.     { init(n); insert(begin(), n, value); }
  349.     list (short n, const T& value,
  350.               const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  351.           : the_allocator(alloc)
  352.     { init(n); insert(begin(), n, value); }
  353.     list (unsigned short n, const T& value,
  354.               const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  355.           : the_allocator(alloc)
  356.     { init(n); insert(begin(), n, value); }
  357.     list (char n, const T& value,
  358.               const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  359.           : the_allocator(alloc)
  360.     { init(n); insert(begin(), n, value); }
  361.     list (unsigned char n, const T& value,
  362.               const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  363.           : the_allocator(alloc)
  364.     { init(n); insert(begin(), n, value); }
  365.     list (bool n, const T& value,
  366.               const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  367.           : the_allocator(alloc)
  368.     { init(n); insert(begin(), n, value); }
  369. #ifndef _RWSTD_NO_OVERLOAD_WCHAR
  370.     list (wchar_t n, const T& value,
  371.               const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  372.           : the_allocator(alloc)
  373.     { init(n); insert(begin(), n, value); }
  374. #endif
  375. #else
  376.     //
  377.     // Build a list of size n with each element set to a copy of value.
  378.     //
  379.     list (size_type n, const T& value, 
  380.                    const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator())) 
  381.          : length(0), the_allocator(alloc), buffer_list(0),
  382.            free_list(0), next_avail(0), last(0)
  383.     {
  384.         init(n);
  385.         insert(begin(), n, value);
  386.     }
  387.  
  388.     list (const_iterator first, const_iterator locallast,
  389.                   const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  390.          : length(0), the_allocator(alloc), buffer_list(0),
  391.            free_list(0), next_avail(0), last(0)
  392.     {
  393.         init();
  394.         insert(begin(), first, locallast);
  395.     }
  396.     list (const T* first, const T* locallast,
  397.                   const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  398.          : length(0), the_allocator(alloc), buffer_list(0),
  399.            free_list(0), next_avail(0), last(0)
  400.     {
  401.         init();
  402.         insert(begin(), first, locallast);
  403.     }
  404.  
  405. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  406.     list (const_iterator first, const_iterator locallast)
  407.          : length(0), the_allocator(Allocator()), buffer_list(0),
  408.            free_list(0), next_avail(0), last(0)
  409.     {
  410.         init();
  411.         insert(begin(), first, locallast);
  412.     }
  413.     list (const T* first, const T* locallast)
  414.          : length(0), the_allocator(Allocator()), buffer_list(0),
  415.            free_list(0), next_avail(0), last(0)
  416.     {
  417.         init();
  418.         insert(begin(), first, locallast);
  419.     }
  420. #endif
  421. #endif
  422.  
  423.     list (const list<T,Allocator>& x) : length(0), buffer_list(0),
  424.            free_list(0), next_avail(0), last(0)
  425.     {
  426.         the_allocator = x.get_allocator();
  427.         init();
  428.         insert(begin(), x.begin(), x.end());
  429.     }
  430.  
  431.     void init(size_type n = 0)  
  432.     {
  433.        buffer_size = max((size_type)1,
  434.                          __RWSTD::__rw_allocation_size((value_type*)0,
  435.                                                        (size_type)0));
  436.        node = get_node(n == 0 ? buffer_size : n);
  437.        (*node).next = node;
  438.        (*node).prev = node; 
  439.     }
  440.  
  441.     ~list ()
  442.     {
  443.         erase(begin(), end());
  444.         put_node(node);
  445.     deallocate_buffers();
  446.     }
  447.     list<T,Allocator>& operator= (const list<T,Allocator>& x);   
  448.  
  449. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  450.     template<class InputIterator>
  451.     void assign (InputIterator first, InputIterator last)
  452.     {
  453.         erase(begin(), end()); insert(begin(), first, last);
  454.     }
  455. #else
  456.     void assign (const_iterator first, const_iterator last)
  457.     {
  458.         erase(begin(), end()); insert(begin(), first, last);
  459.     }
  460.     void assign (const T* first, const T* last)
  461.     {
  462.         erase(begin(), end()); insert(begin(), first, last);
  463.     }
  464. #endif
  465.     //
  466.     // Assign n copies of default value of type T to list.
  467.     // This requires that T have a default constructor.
  468.     //
  469. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  470.     template<class Size>
  471.     void assign (Size n)
  472. #else
  473.     void assign (size_type n)
  474. #endif
  475.     {
  476.         erase(begin(), end()); insert(begin(), n, T());
  477.     }
  478.     //
  479.     // Assign n copies of t to this list.
  480.     //
  481. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  482.     template<class Size, class U>
  483.     void assign (Size n, const U& t)
  484. #else
  485.     void assign (size_type n, const T& t)
  486. #endif
  487.     {
  488.         erase(begin(), end()); insert(begin(), n, t);
  489.     }
  490.     allocator_type get_allocator() const
  491.     {
  492.         return the_allocator;
  493.     }
  494.  
  495.     public:
  496.  
  497.     //
  498.     // Iterators.
  499.     //
  500.   iterator       begin ()       { return _RWSTD_STATIC_CAST(link_type,((*node).next)); }
  501.   const_iterator begin () const { return _RWSTD_STATIC_CAST(link_type,((*node).next)); }
  502.  
  503.     iterator       end ()         { return node;                      }
  504.     const_iterator end ()   const { return node;                      }
  505.     reverse_iterator rbegin ()
  506.     { 
  507.         reverse_iterator tmp(end()); return tmp;
  508.     }
  509.     const_reverse_iterator rbegin () const
  510.     { 
  511.         const_reverse_iterator tmp(end()); return tmp;
  512.     }
  513.     reverse_iterator rend ()
  514.     { 
  515.         reverse_iterator tmp(begin()); return tmp;
  516.     }
  517.     const_reverse_iterator rend () const
  518.     {
  519.         const_reverse_iterator tmp(begin()); return tmp;
  520.     }
  521.  
  522.     //
  523.     // Capacity.
  524.     //
  525.     bool empty ()         const { return length == 0;                }
  526.     size_type size ()     const { return length;                     }
  527.     size_type max_size () const 
  528.     { return list_node_alloc_type(the_allocator).max_size(); }
  529.     void resize (size_type new_size);
  530.     void resize (size_type new_size, T value);
  531.  
  532.     //
  533.     // Element access.
  534.     //
  535.     reference       front ()       { return *begin();   }
  536.     const_reference front () const { return *begin();   }
  537.     reference       back  ()       { return *(--end()); }
  538.     const_reference back  () const { return *(--end()); }
  539.  
  540.     //
  541.     // Modifiers.
  542.     //
  543.     //
  544.     // Insert default value of type T at position.
  545.     // Requires that T have a default constructor.
  546.     //
  547.     iterator insert (iterator position)
  548.     {
  549.         value_alloc_type va(the_allocator);
  550.         link_type tmp = get_node(buffer_size);
  551.         va.construct(va.address((*tmp).data),T());
  552.         (*tmp).next = position.node;
  553.         (*tmp).prev = (*position.node).prev;
  554.         (*(link_type((*position.node).prev))).next = tmp;
  555.         (*position.node).prev = tmp;
  556.         ++length;
  557.         return tmp;
  558.     }
  559.     //
  560.     // Insert x at position.
  561.     //
  562.     iterator insert (iterator position, const T& x)
  563.     {
  564.         value_alloc_type va(the_allocator);
  565.         link_type tmp = get_node(buffer_size);
  566.         va.construct(va.address((*tmp).data),x);
  567.         (*tmp).next = position.node;
  568.         (*tmp).prev = (*position.node).prev;
  569.         (*(link_type((*position.node).prev))).next = tmp;
  570.         (*position.node).prev = tmp;
  571.         ++length;
  572.         return tmp;
  573.     }
  574.  
  575. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  576.     template<class InputIterator>
  577.     void insert (iterator position, InputIterator first, 
  578.                                     InputIterator last);
  579.     void insert (iterator position, int n, const T& value)
  580.     { insert_aux(position,(size_type)n,value); }
  581.     void insert (iterator position, unsigned int n, const T& value)
  582.     { insert_aux(position,(size_type)n,value); }
  583.     void insert (iterator position, long n, T value)
  584.     { insert_aux(position,(size_type)n,value); }
  585.     void insert (iterator position, unsigned long n, const T& value)
  586.     { insert_aux(position,(size_type)n,value); }
  587.     void insert (iterator position, short n, const T& value)
  588.     { insert_aux(position,(size_type)n,value); }
  589.     void insert (iterator position, unsigned short n, const T& value)
  590.     { insert_aux(position,(size_type)n,value); }
  591.     void insert (iterator position, char n, const T& value)
  592.     { insert_aux(position,(size_type)n,value); }
  593.     void insert (iterator position, unsigned char n, const T& value)
  594.     { insert_aux(position,(size_type)n,value); }
  595.     void insert (iterator position, bool n, const T& value)
  596.     { insert_aux(position,(size_type)n,value); }
  597. #ifndef _RWSTD_NO_OVERLOAD_WCHAR
  598.     void insert (iterator position, wchar_t n, const T& value)
  599.     { insert_aux(position,(size_type)n,value); }
  600. #endif
  601. #else
  602.     void insert (iterator position, size_type n, const T& x)
  603.     { insert_aux(position,n,x); }
  604.     void insert (iterator position, const T* first, const T* last);
  605.     void insert (iterator position, const_iterator first, const_iterator last);
  606. #endif
  607.  
  608.     iterator erase (iterator position)
  609.     {
  610.         if (position == end())
  611.            return end();
  612.         iterator tmp = (iterator)(link_type((*position.node).next));
  613.         (*(link_type((*position.node).prev))).next = (*position.node).next;
  614.         (*(link_type((*position.node).next))).prev = (*position.node).prev;
  615.         value_alloc_type va(the_allocator);
  616.         va.destroy(va.address((*position.node).data));
  617.         put_node(position.node);
  618.         --length;
  619.         return tmp;
  620.     }
  621.     iterator erase      (iterator first, iterator last);
  622.     void push_front (const T& x) { insert(begin(), x); }
  623.     void push_back  (const T& x) { insert(end(), x);   }
  624.     void pop_front  ()           { erase(begin());     }
  625.     void pop_back   ()           { iterator tmp = end(); erase(--tmp); }
  626.     void swap (list<T,Allocator>& x)
  627.     {
  628.      if(the_allocator==x.the_allocator)
  629.       {
  630.  
  631. #ifndef _RWSTD_NO_NAMESPACE
  632.         std::swap(node, x.node); 
  633.         std::swap(length, x.length);
  634.         std::swap(buffer_list,x.buffer_list);
  635.         std::swap(free_list,x.free_list);
  636.         std::swap(next_avail,x.next_avail);
  637.         std::swap(last,x.last);
  638. #else
  639.         ::swap(node, x.node); 
  640.         ::swap(length, x.length);
  641.         ::swap(buffer_list,x.buffer_list);
  642.         ::swap(free_list,x.free_list);
  643.         ::swap(next_avail,x.next_avail);
  644.         ::swap(last,x.last);
  645. #endif
  646.       }
  647.       else
  648.       {
  649.         list<T,Allocator> _x = *this;
  650.         *this=x;
  651.         x=_x;
  652.       }
  653.     }
  654.  
  655.     void clear()
  656.     {
  657.         erase(begin(),end());
  658.     }
  659.  
  660.   protected:
  661.     
  662.     void transfer (iterator position, iterator first, 
  663.                    iterator last, list<T,Allocator>& x)
  664.     {
  665.       if (this == &x)
  666.       {
  667.         (*(link_type((*last.node).prev))).next = position.node;
  668.         (*(link_type((*first.node).prev))).next = last.node;
  669.         (*(link_type((*position.node).prev))).next = first.node;  
  670.         link_type tmp = link_type((*position.node).prev);
  671.         (*position.node).prev = (*last.node).prev;
  672.         (*last.node).prev = (*first.node).prev; 
  673.         (*first.node).prev = tmp;
  674.       }
  675.       else
  676.       {
  677.         insert(position,first,last);
  678.         x.erase(first,last);
  679.       }
  680.     }
  681.  
  682.     // used by the sort() member function
  683.     void set_allocator(allocator_type a)
  684.     {  
  685.         the_allocator = a; 
  686.     }
  687.     void insert_aux (iterator position, size_type n, const T& x);
  688.  
  689.   public:
  690.  
  691.     //
  692.     // list operations.
  693.     //
  694.     void splice (iterator position, list<T,Allocator>& x)
  695.     {
  696.         if (!x.empty())
  697.             transfer(position, x.begin(), x.end(), x);
  698.     }
  699.     void splice (iterator position, list<T,Allocator>& x, iterator i)
  700.     { 
  701.         iterator k = i;
  702.         if (k != position && ++k != position)
  703.         {
  704.           iterator j = i;
  705.           transfer(position, i, ++j, x);
  706.         }
  707.     }
  708.     void splice (iterator position, list<T,Allocator>& x, iterator first, iterator last)
  709.     {
  710.         if (first != last)
  711.         {
  712.             difference_type n;
  713.             __initialize(n, difference_type(0));
  714.             distance(first, last, n);
  715.             transfer(position, first, last, x);
  716.         }
  717.     }
  718.     void remove  (const T& value);
  719.     void unique  ();
  720.     void merge   (list<T,Allocator>& x);
  721.     void reverse ();
  722.     void sort    ();
  723.  
  724. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  725.     template<class Predicate>       void remove_if (Predicate pred);
  726.     template<class BinaryPredicate> void unique    (BinaryPredicate pred);
  727.     template<class Compare>         void merge     (list<T,Allocator>& x, Compare comp);
  728.     template<class Compare>         void sort      (Compare comp);
  729. #endif
  730.  
  731. #ifndef _RWSTD_STRICT_ANSI
  732.     // Non-standard function for setting buffer allocation size
  733.     size_type allocation_size() { return buffer_size; }
  734.     size_type allocation_size(size_type new_size) 
  735.     { 
  736.        size_type tmp = buffer_size; 
  737.        buffer_size = max((size_type)1,new_size);
  738.        return tmp;
  739.     }
  740. #endif   
  741. };
  742.  
  743. template <class T, class Allocator>
  744. inline bool operator== (const list<T,Allocator>& x, const list<T,Allocator>& y)
  745. {
  746.     return x.size() == y.size() && equal(x.begin(), x.end(), y.begin());
  747. }
  748.  
  749. template <class T, class Allocator>
  750. inline bool operator< (const list<T,Allocator>& x, const list<T,Allocator>& y)
  751. {
  752.     return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
  753. }
  754.  
  755. #if !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  756. template <class T, class Allocator>
  757. inline bool operator!= (const list<T,Allocator>& x, const list<T,Allocator>& y)
  758. {
  759.     return !(x == y);
  760. }
  761.  
  762. template <class T, class Allocator>
  763. inline bool operator> (const list<T,Allocator>& x, const list<T,Allocator>& y)
  764. {
  765.     return y < x;
  766. }
  767.  
  768. template <class T, class Allocator>
  769. inline bool operator>= (const list<T,Allocator>& x, const list<T,Allocator>& y)
  770. {
  771.     return !(x < y);
  772. }
  773.  
  774. template <class T, class Allocator>
  775. inline bool operator<= (const list<T,Allocator>& x, const list<T,Allocator>& y)
  776. {
  777.     return !(y <  x);
  778. }
  779.  
  780. template <class T, class Allocator>
  781. inline void swap(list<T,Allocator>& a, list<T,Allocator>& b)
  782. {
  783.     a.swap(b);
  784. }
  785. #endif
  786.  
  787. #ifndef _RWSTD_NO_NAMESPACE
  788. }
  789. #endif
  790.  
  791. #ifdef _RWSTD_NO_TEMPLATE_REPOSITORY
  792. #include <list.cc>
  793. #endif
  794.  
  795. #undef list
  796.  
  797. #pragma option pop
  798. #endif /*__STD_LIST__*/
  799.